package com.zbzly.reactive.reactiverbac.controller;

import com.zbzly.reactive.reactiverbac.mapper.ReactiveUserRepository;
import com.zbzly.reactive.reactiverbac.model.po.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/user")
@Tag(name = "user")
public class ReactiveUserController {
    @Resource
    private ReactiveUserRepository reactiveUserRepository;

    @GetMapping("/")
    @Operation(summary = "hello")
    public Mono<String> getUser() {
        return Mono.just("Hello World");
    }

    @Operation(summary = "获取所有用户")
    @GetMapping(value = "/list",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<User> getUserList() {
        return reactiveUserRepository.findAll();
    }
}
